﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Aleator.Helpers
{
    public static class Logger
    {
        private static TraceSource _ts = new TraceSource("aleatorTraceSource");
        private static TextWriterTraceListener _twtl = new TextWriterTraceListener(string.Format("C:\\Logs\\aleator_{0}.log", DateTime.Now.ToString("yyyyMMdd_HHmm")));
        private static EventLogTraceListener _eltl = new EventLogTraceListener("Aleator");

        static Logger()
        {
            _ts.Switch = new SourceSwitch("aleatorSwitch", "Aleator switch");
            _ts.Switch.Level = SourceLevels.Information;

            //_twtl.TraceOutputOptions = TraceOptions.DateTime;
            _eltl.Filter = new EventTypeFilter(SourceLevels.Error);

            _ts.Listeners.Clear();
            _ts.Listeners.Add(_twtl);
            _ts.Listeners.Add(_eltl);

            Trace.AutoFlush = true;
        }

        /// <summary>
        /// Log the message
        /// </summary>
        /// <param name="traceeventtype"></param>
        /// <param name="message"></param>
        public static void Log(TraceEventType traceeventtype, string message)
        {
            _ts.TraceEvent(traceeventtype, 0, message);
        }
    }
}
